<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title></title>
	<link href="css/mui.min.css" rel="stylesheet" />
	<link rel="stylesheet" href="css/iconfont.css" />
	<style>
		ul {
			font-size: 14px;
			color: #8f8f94;
		}

		.mui-btn {
			padding: 10px;
		}

		.selectcorlor {
			color: #007aff
		}

		.unselectcorlor {
			color: #929292
		}
	</style>
</head>

<body>

	<div class="mui-content"> </div>
	<nav class="mui-bar mui-bar-tab" id="bottomx">
		<a id="index" href="carlist" class="mui-tab-item mui-active"> <span
				class="mui-icon iconfont icon-jiaoche"></span> <span class="mui-tab-label">轿车</span> </a>
		<a id="huoche" href="huoche" class="mui-tab-item"> <span class="mui-icon iconfont icon-huoche"></span> <span
				class="mui-tab-label">货车</span> </a>
		<a id="fabu" href="fabu" class="mui-tab-item"> <span class="mui-icon iconfont icon-fabu"></span> <span
				class="mui-tab-label">发布</span> </a>
		<a id="wodefabu" href="wodefabu" class="mui-tab-item"> <span class="mui-icon iconfont icon-wodefabu"></span>
			<span class="mui-tab-label">我的发布</span> </a>
		<a id="member" href="member" class="mui-tab-item"> <span class="mui-icon iconfont icon-wodedangxuan"></span>
			<span class="mui-tab-label">我的</span> </a>
	</nav>
	<script src="js/mui.min.js"></script>
	<script src="js/app.js"></script>
	<script type="text/javascript" src="script/jquery-3.3.1.min.js"></script>
	<script>
		var carportid;
		var truckportid;
		(function ($, doc) {
				console.log("[main.html]init...");
				$.init();
				console.log("[main.html]init完毕");

				var subpage_style = {
					top: '0px',
					bottom: '50px'
				};

				//=================获取不重复的uuid  start====================
				function S4() {
					return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
				}

				function guid() {
					return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
				}
				//=================获取不重复的uuid  end=============================================
				var subpages = ['index1.html'];
				var aid = "";
				$.plusReady(function () {
					var self = plus.webview.currentWebview();
					//获取前面页中的extras中的参数 
					carportid = self.ids;
					truckportid = self.idss;
					//						alert(carportid);
					//						mui.trigger(document.getElementById("index"),'touchstart');
					//						mui.trigger(document.getElementById("index"),'tap');

					var toJiaoche = function () {
						setTimeout(function () {

							$.openWindow({
								url: 'carlist.html',
								id: "cms" + guid(),
								extras: {
									flag: true //扩展参数
								},
								show: {
									aniShow: 'none'
								},
								styles: subpage_style,
								waiting: {
									autoShow: false
								}
							});
						}, 0);
					};
					var toHuoche = function () {
						//$.fire(activityPage, 'show', null);
						setTimeout(function () {
							$.openWindow({
								url: 'list.html',
								id: "cms" + guid(),
								preload: true,
								createNew: true,
								show: {
									aniShow: 'none'
								},
								styles: subpage_style,
								waiting: {
									autoShow: false
								},
								extras: {
									aaid: aid //传递菜单id
								}
							});
						}, 0);
					};
					var toFabu = function () {
						//$.fire(activityPage, 'show', null);
						setTimeout(function () {
							$.openWindow({
								url: 'report.html',
								id: "cms" + guid(),
								preload: false,
								show: {
									aniShow: 'none'
								},
								styles: subpage_style,
								waiting: {
									autoShow: false
								}
							});
						}, 0);
					};
					//我的发布
					var toMyFabu = function () {
						//$.fire(activityPage, 'show', null);
						setTimeout(function () {
							$.openWindow({
								url: 'mysubscribe.html',
								id: "cms" + guid(),
								preload: false,
								show: {
									aniShow: 'none'
								},
								styles: subpage_style,
								waiting: {
									autoShow: false
								}
							});
						}, 0);
					};
					//我的
					var toMyPage = function () {
						//$.fire(activityPage, 'show', null);
						setTimeout(function () {
							$.openWindow({
								url: 'member.html',
								id: "cms" + guid(),
								preload: false,
								show: {
									aniShow: 'none'
								},
								styles: subpage_style,
								waiting: {
									autoShow: false
								}
							});
						}, 0);
					};
					//我的
					var toMyPageNew = function () {
						//$.fire(activityPage, 'show', null);
						setTimeout(function () {
							$.openWindow({
								url: 'member.html',
								id: "cms" + guid(),
								preload: false,
								createNew: true,
								show: {
									aniShow: 'none'
								},
								styles: subpage_style,
								waiting: {
									autoShow: false
								}
							});
						}, 0);
					};


					//当前激活选项
					var activeTab = subpages[0];
					//当前的webview对象，应该为一个只有头和尾的
					var self = plus.webview.currentWebview();
					//获取前面页中的extras中的参数
					/**
					 * 退出登录时，直接打开到‘我的’页面
					 */
					aid = self.aid; //对应的一级菜单和二级菜单的id
					console.log(aid + "-------------------");
					var targetPage = self.targetPage;
					console.log("[main.html------]" + targetPage);


					if (typeof (carportid) != "undefined") {
						var tab1 = doc.getElementById("index");
						tab1.classList.add("mui-active");

					}

					//truckportid
					if (typeof (truckportid) != "undefined") {
						var tab = doc.getElementById("index");
						tab.classList.remove("mui-active");
						var tab1 = doc.getElementById("huoche");
						tab1.classList.add("mui-active");
						targetPage = 'list.html';
						//								toHuoche();
						//								return;
					}

					if (targetPage == 'myPages.html') {
						activeTab = targetPage;

						//为优化内存，关闭所有webview，只保留当前
						var all = plus.webview.all();
						var current = plus.webview.currentWebview().id;
						for (var i = 0, len = all.length; i < len; i++) {
							if (all[i].id !== 'HBuilder' && all[i].id !== 'main') {
								console.log(all[i].id + "--------" + current);
								all[i].close();
							}
						}
						toMyPageNew();
						//底部默认激活在‘首页’，需放在‘我的’页面							
						var tab = doc.getElementById("index");
						tab.classList.remove("mui-active");
						var tab1 = doc.getElementById("member");
						tab1.classList.add("mui-active");
					} else if (targetPage == 'mysubscribe.html') {
						activeTab = targetPage;
						toMyFabu();
						var tab = doc.getElementById("index");
						tab.classList.remove("mui-active");
						var tab1 = doc.getElementById("wodefabu");
						tab1.classList.add("mui-active");

					} else if (targetPage == 'report.html') {
						activeTab = targetPage;
						toFabu();
						var tab = doc.getElementById("index");
						tab.classList.remove("mui-active");
						var tab1 = doc.getElementById("fabu");
						tab1.classList.add("mui-active");

					} else if (targetPage == 'list.html') {
						activeTab = targetPage;
						toHuoche();
						var tab = doc.getElementById("index");
						tab.classList.remove("mui-active");
						var tab1 = doc.getElementById("huoche");
						tab1.classList.add("mui-active");
					} else {
						toJiaoche();
						//window.location.href = "index1.html";
					}



					console.log("当前View" + JSON.stringify(self));
					$.oldBack = mui.back;
					var backButtonPress = 0;
					$.back = function (event) {
						backButtonPress++;
						if (backButtonPress > 1) {
							plus.runtime.quit();
						} else {
							plus.nativeUI.toast('再按一次退出应用');
						}
						setTimeout(function () {
							backButtonPress = 0;
						}, 1000);
						return false;
					};



					//var title = doc.getElementById("title");
					//选项卡点击事件
					mui('.mui-bar-tab').on('tap', 'a', function (e) {
						var targetTab = this.getAttribute('href');
						console.log("点击了" + JSON.stringify(targetTab));
						switch (targetTab) {
							case 'huoche':
								toHuoche();
								break;
							case 'wodefabu':
								toMyFabu();
								break;
							case 'fabu':
								toFabu();
								break;
							case 'member':
								toMyPage();
								break;
							default:
								toJiaoche();
						}
					});
				});
				//					


			}
			(mui, document));
	</script>

</body>

</html>